package com.sunny.dfs;

import java.util.*;

public class Main {

    public static void main(String[] args) {

        Set<Integer> set = new HashSet<>();
        List<Integer> list = Arrays.asList(1,2,3,4,5);

        dfs(list, 0, set);
    }

    public static void dfs(List<Integer> list, int ind, Set<Integer> set){

        if(ind == list.size()){
            System.out.println("结果为：");
            set.forEach(System.out::print);
            System.out.println();
            return;
        }

        dfs(list, ind+1, set);
        set.add(list.get(ind));
        dfs(list, ind+1, set);
        set.remove(list.get(ind));//注意此处必须remove，否则会影响结果


    }

}
